package pers.wensheng.patterns.behavioral_pattern.memento_pattern.white_box;

/**
 * 备忘录模式
 * 白箱模式：在管理者里面可以访问一些数据
 */
public class Client {
    public static void main(String[] args) {

        //创建管理者
        RoleStateCaretaker roleStateCaretaker = new RoleStateCaretaker();
        //创建角色
        GameRole gameRole = new GameRole();
        gameRole.initState();

        System.out.println("------------大战Boss前------------");
        System.out.println(gameRole);

        //备份
        RoleStateMemento roleStateMemento = gameRole.saveState();
        roleStateCaretaker.setRoleStateMemento(roleStateMemento);

        System.out.println("------------大战Boss后------------");
        gameRole.fight();
        System.out.println(gameRole);


        System.out.println("----------------可以获取和修改备忘录信息-----------------");
        RoleStateMemento stateMemento = roleStateCaretaker.getRoleStateMemento();
        stateMemento.setDef(50);
        System.out.println(stateMemento.getDef());


        System.out.println("------------恢复之前状态------------");
        gameRole.recoverState(roleStateCaretaker.getRoleStateMemento());
        System.out.println(gameRole);

    }
}
